﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using Fusion.Data.Contract;
using Fusion.Data.Domain;
using Fusion.Common;

namespace Fusion.Data
{
    public class EntityProvider : IEntityProvider
    {
        private FusionDBEntities _context = null;
        public EntityProvider()
        {
            if(_context == null)
                _context = new FusionDBEntities(Globals.GetModelConnectionString());
        }


        public bool CreateEntityRecord(string type, List<MethodParameter> parameters)
        {
            Customers customer = new Customers();
            customer.Email = "fyasar@gmail.com";
            customer.Name = "Fatih YAŞAR";
            customer.Telephone = "0533 5700869";

            _context.AddToCustomers(customer);
            _context.SaveChanges();
            return true;
        }


        public bool IsEntityExist(string type)
        {
            //_context.MetadataWorkspace.TryGetType("Customers", "Fusion.Data.Domain", true, System.Data.Metadata.Edm.DataSpace.CSSpace, out tx);
            Type t = Type.GetType("Fusion.Data.Domain." + type);
            Console.WriteLine("type : " + t);
            return true;
        }

        public bool CreateEntity(string type, List<ColumnParameter> columnParameters)
        {
            IsEntityExist("Customers");
            return true;
        }

    }
}
